postman自动记录执行结果

您所在的位置:网站首页 新版postman runner入口 postman自动记录执行结果

postman自动记录执行结果

2023-11-06 00:29| 来源: 网络整理| 查看: 265

问题

解决场景测与没测,结果对与不对纠纷

避免测试时结果是对的,后期代码改动造成结果错误导致的内容不确定

同一场景下,历史逻辑、返回结果的反查

极简方案

1、在history tab中,打开save Response 选项,自动记录历史请求和response

完善方案

将每次请求、结果都自动保存到本地文件中,以备查用

https://github.com/sivcan/ResponseToFile-Postman 结合这个本地服务实现保存功能

使用方法:

Put all the requests you want to write the responses for, under this collection.

1、Clone the following repository to your machine - https://github.com/sivcan/ResponseToFile-Postman or use the following command - git clone https://github.com/sivcan/ResponseToFile-Postman

Navigate into the directory and install the dependencies. Use the following command: npm i

如果没有npm,通过安装nodejs一起安装https://nodejs.org/en/

3、Run the local server. Use the following command: node script.js

Now, the responses for every request which is a part of this collection will be written to the Responses folder inside the project repo. You can modify the local server's code to change the file location.

Run your requests through builder / run through collection runner and store your data locally.

上面整个项目入口代码在 script.js文件中

可以对默认的文件存储路径进行修改

以下修改

/* 生成年月日用于按日期存储文件 */ function getTimeInfo() { var date = new Date; var year = date.getFullYear(); var month = date.getMonth()+1; month = (month // The opts for the server, also includes the data to be written to file let opts = { requestName: request.name || request.url, fileExtension: 'json', mode: 'writeFile', // Change this to any function of the fs library of node to use it. uniqueIdentifier: true, requestData:pm.request.body.raw || request.url, responseData: pm.response.text() }; pm.sendRequest({ url: 'http://localhost:3000/write', method: 'POST', header: 'Content-Type:application/json', body: { mode: 'raw', raw: JSON.stringify(opts) } }, function (err, res) { console.log(res); });



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3